<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="组号">
              <a-input placeholder="请输入..." v-model="queryParam.dbfzbh"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="学号">
              <a-input placeholder="请输入..." v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="姓名">
              <a-input placeholder="请输入..." v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="学生类别">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.xslbm">
                    <a-select-option v-for="i in TYPE0075" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="院系">
                  <a-select :allowClear="true" :disabled="selectYxConfig.length === 1" showSearch optionFilterProp="children" v-model="queryParam.yx" @change="handleSelectYx">
                    <a-select-option v-for="i in selectYxConfig" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="专业">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zy">
                    <a-select-option v-for="i in selectZyConfig" :key="i.zyh" :value="i.zyh">{{ i.zyh+'-'+i.zymc }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="年度">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.dbnd">
                    <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
          </template>
          <a-col :sm="{span:24}" :xl="{span:advanced?24:12}" style="text-align:center">
            <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    
    <a-card class="card" :bordered="false">
    <STable
      v-if="initDone"
      ref="table"
      size="default"
      rowKey="dbfzbh"
      :columns="columns"
      :alert="{ show: true }"
      :data="loadData">

      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
      <a slot="dbfzbh" slot-scope="text, record, index" @click="handleOpenDetail(record)">{{text}}</a>
      <span slot="dbrq" slot-scope="text, record, index">{{ text | dateYMD }} {{ record.dbrqswhxwmc }}</span>
    </STable>
    </a-card>
    <groupPrev ref="groupPrev" :prevVisible="prevVisible" @close="handleEditClose"  :data="currentInfo" />
</div>
</template>

<script>
import moment from 'moment'
import groupPrev from './groupPrev.vue'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = [
  'TYPE0126', //年级
  'TYPE0075' //学生类别
]

export default {
  components: {
    STable,
    groupPrev
  },
  filters:{
    dateYMD:function(value){
      return moment(value).format('YYYY-MM-DD')
    }
  },
  data () {
    return {
      advanced: true,
      prevVisible:false,
      // 条件配置
      selectYxConfig: [], //院系
      selectZyConfig: [], //专业 
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '组号',
          dataIndex: 'dbfzbh',
          scopedSlots: { customRender: 'dbfzbh' },
        },
        {
          title: '答辩日期',
          dataIndex: 'dbrq',
          scopedSlots: { customRender: 'dbrq' }
        },
        {
          title: '答辩地点',
          dataIndex: 'dbdd'
        },
        {
          title: '专业名称',
          dataIndex: 'zymc'
        },
        {
          title: '审核状态',
          dataIndex: 'shjgmc'
        },
        {
          title: '学生类别',
          dataIndex: 'xslbmc'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        return this.$api.degree.pleaGroupList(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      //当前明细 分组信息
      currentInfo:{},
      initDone: false
    }
  },
  computed: {
    ...mapState({
      TYPE0075: state => state.app['TYPE0075'], // 学生类别
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()

    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectYxConfig = res[0].data
        if (res[0].data.length === 1) {
          this.$set(this.queryParam, 'yx', res[0].data[0].dwh)
          this.handleSelectYx(res[0].data[0].dwh)
        }
        this.initDone = true
      })
    },
     //打开修改
    handleOpenDetail(record){
      this.currentInfo = record;
      this.$nextTick(()=>{
        this.prevVisible = true;
      })
    },
    // 关闭添加弹层
    handleEditClose() {
      this.prevVisible = false
    },
    //选择院系
    handleSelectYx(code) {
      this.selectZyConfig = [];
      this.$set(this.queryParam,"zy","");
      this.$api.base.majorAll({ lsdwh: code }).then(res => {
        this.selectZyConfig = res.data;
      })
    },
    // 导出
    handleExport () {
      this.$export('/degree/dbfzxx/exp', this.queryParam)
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
